/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package linkeddata.arida.ufc.br.servlet;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import linkeddata.arida.ufc.br.manager.impl.ExecuteQueryJena;

/**
 *
 * @author jeovane
 */
public class ExecuteQueryJenaServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String queryString = request.getParameter("queryString");
        String endpoint = request.getParameter("endpoint");
        String query = "";
        List<String> varsQuery = null;

        ExecuteQueryJena executeQueryJena = new ExecuteQueryJena(endpoint, queryString);

        try {
            //varsQuery = executeQueryJena.listVarSelect();
            //resultQuery = executeQueryJena.resultListQuery();
            //mapQuery = executeQueryJena.resultQuery();
            query = executeQueryJena.printQueryXML();
        } catch (Exception ex) {
            System.out.println("Erro: " + ex.getMessage());
        }
        
        //String vQuery = new Gson().toJson(varsQuery);
        //String rQuery = new Gson().toJson(resultQuery);
        //String mQuery = new Gson().toJson(mapQuery);

        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
        //String bothJson = "[" + vQuery + "," + rQuery + "]";
        //response.getWriter().write(bothJson);
        //response.getWriter().write(mQuery);
        response.getWriter().write(query);
    }
}
